library IEEE;
use IEEE.NUMERIC_STD.ALL;

entity reentrant is
    Port ( inputa, inputb : in  unsigned (31 downto 0);
           output : out unsigned (31 downto 0));
end reentrant;

architecture Behavioral of reentrant is
	signal pix1a,pix2a,pix3a,pix4a: unsigned (7 downto 0);
	signal pix1b,pix2b,pix3b,pix4b: unsigned (7 downto 0);
	signal sad1,sad2,sad3,sad4: unsigned (7 downto 0);
begin
	pix1a <= inputa (31 downto 24);
	pix2a <= inputa (23 downto 16);
	pix3a <= inputa (15 downto 8);
	pix4a <= inputa (7 downto 0);
	pix1b <= inputb (31 downto 24);
	pix2b <= inputb (23 downto 16);
	pix3b <= inputb (15 downto 8);
	pix4b	<= inputb (7 downto 0);	
	sad1 <= unsigned(abs(signed(pix1a - pix1b))); 
	sad2 <= unsigned(abs(signed(pix2a - pix2b)));
	sad3 <= unsigned(abs(signed(pix3a - pix3b)));
	sad4 <= unsigned(abs(signed(pix4a - pix4b)));
	output <= resize(sad1,32)+resize(sad2,32)+resize(sad3,32)+resize(sad4,32);
end Behavioral;

